package cz.semjob.learning.learner;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import weka.classifiers.Classifier;
import weka.classifiers.trees.RandomForest;
import weka.core.Instances;
import cz.semjob.learning.classifier.LearningException;

@Component
public class RandomForestDataSetLearner implements IDataSetLearner {

	private static Logger logger = Logger
			.getLogger(RandomForestDataSetLearner.class);

	public Classifier buildClassifier(Instances instances)
			throws LearningException {
		RandomForest classifier = new RandomForest();
		classifier.setNumTrees(30);

		try {
			classifier.buildClassifier(instances);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
			throw new LearningException(e);
		}
		return classifier;
	}

	public String getInfo() {
		return "RandomForest";
	}
}
